/* 
 * Copyright (C) 2012 UTSChedule
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package utsc.apps.utschedule.widget;

import utsc.apps.utschedule.R;
import utsc.apps.utschedule.util.AppUtils;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * This is a custom layout widget for showing as a clickable region on the {@link utsc.apps.utschedule.widget.TimeBlockLayout TimeBlockLayout}.
 * @author Wenbin
 *
 */
public class TimeBlockView extends BlockView {

	private int _height,_width;
	
	public TimeBlockView(Context context, int _hourPosition, int _columnPosition,int width,int height, int contentViewResID) {

		super(context);
		this._hourPosition = _hourPosition;
		this._columnPosition = _columnPosition;
		this._width=width;
		this._height=height;
	    
		LayoutInflater.from(context).inflate(R.layout.timeblockview, this,true);
		
		setupContentView();

		setBackgroundDrawable(AppUtils.getColorCustomizableDrawable(context, R.drawable.btn_block,  Color.CYAN, 1, 0).get());
		
	}
	
	
	private TextView _txtView;

	@Override
	protected void setupContentView() {
		_contentView=(LinearLayout)findViewById(R.id.blockview_layout);
		_txtView=(TextView) findViewById(R.id.blockview_txt);
		_txtView.setText("+");
		_txtView.setTextColor(Color.WHITE);
		_txtView.setTextSize((_height-_paddingOffset*3)/getResources().getDisplayMetrics().scaledDensity);
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		setMeasuredDimension(resolveSize(_width, widthMeasureSpec),
                resolveSize(_height, heightMeasureSpec));
	}
	
	@Override
	protected void onLayout(boolean changed, int left, int top, int right,
			int bottom) {

		_contentView.measure(MeasureSpec.makeMeasureSpec(getWidth()-_paddingOffset*2, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(getHeight()-_paddingOffset*2, MeasureSpec.EXACTLY));
		_contentView.layout(0+_paddingOffset, 0+_paddingOffset, getWidth()-_paddingOffset, getHeight()-_paddingOffset);
		
	}
	
}
